//
//  FFWalletRechargeVC.m
//  LLWallet
//
//  Created by tt on 2020/8/17.
//

#import "FFWalletRechargeVC.h"

@interface FFWalletRechargeVC ()<FFWalletRechargeVMDelegate>

@end

@implementation FFWalletRechargeVC

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.viewModel = [FFWalletRechargeVM new];
        self.viewModel.delegate = self;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到当前view
    [self.tableView addGestureRecognizer:tapGestureRecognizer];
    
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
}

- (NSString *)langTitle {
    return LLang(@"充值");
}

-(NSString*) noDataText {
    return LLang(@"充值功能暂时关闭");
}

-(void) keyboardHide {
    [self.view endEditing:YES];
}

#pragma mark - FFWalletRechargeVMDelegate

- (void)ff_walletRechargeMoneyClick:(FFRechargeMoney *)money {
    [self reloadData];
}

- (void)ff_walletRechargeMoneyChange:(CGFloat)money {
    self.items = [NSMutableArray arrayWithArray: [self.viewModel tableSections]];
    [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}

- (void)ff_walletRechargePayTypeSelected {
    [self reloadData];
}

- (void)ff_walletRecharge {
    [self.view showHUD];
    __weak typeof(self) weakSelf = self;
    [self.viewModel recharge].then(^(FFPrepayResult *result){
        [weakSelf.view hideHud];
        [[FFPayResultManager shared] ff_handlePrepayResult:result];
    }).catch(^(NSError *error){
        [weakSelf.view switchHUDError:error.domain];
    });
}

@end
